docker_root_path="/opt/soft/docker"
container_name="jenkins"
DIR=$( dirname "$(readlink -f  ${BASH_SOURCE[0]})" )
PARENTPATH=$(dirname ${DIR})
result=`sh ${PARENTPATH}/valid_docker_images.sh jenkins`
if [[ $result == "installed" ]]
then
  echo "has installed , Please use force reinstall..."
fi
if [[ -d ${docker_root_path}/jenkins/data ]]
then
  sudo mkdir -p ${docker_root_path}/jenkins/data
fi
docker ps -a | grep -E ${container_name}
if [[ $? -eq 0 ]]
then
  echo "stopping . . . please wait 10S"
  docker stop ${container_name}
  sleep 10
fi
docker run \
  -u root \
  --rm \
  -d \
  -p 8080:8080 \
  -p 50000:50000 \
  --name jenkins \
  -v ${docker_root_path}/jenkins/data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkins/jenkins:2.418
